<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue的生命周期及勾子函数</title>
    <script src="./js/vue.js"></script>
</head>

<body>
    <div class="box">
        <h1>{{msg}}</h1>
        <button v-on:click="test">test</button>
        <div ref="testDom">测试能否操作Dom</div>
        <button @click="del">销毁vue实例</button>
    </div>
    <script>
        const vm = new Vue({
            el: '.box',
            data: {
                msg: 'hello'
            },
            methods: {
                test() {
                    console.log('test哪个时刻能使用！');
                    this.msg = 'nihao';
                },
                del() {
                    this.$destroy();//销毁实例
                }
            },
            //vue实例创建前 data、methods computed directives 都未初始化  根元素el也未初始化
            beforeCreate(){
                console.log('beforeCreate');
                console.log(this.msg);
                console.log(this.test);
                console.log(this.$el);
            },
            //vue实例创建后 data methods computed directives 配置项都初始化 但 根元素未初始化 不能操作Dom元素
            cteated(){
                console.log('create');
                console.log(this.msg);
                console.log(this.test);
                console.log(this.$el);
            },
            //vue实例挂载前 实例 配置项都初始化完成，根元素也初始化完成 但是无法操作Dom
            beforeMount(){
                console.log('beforeMount');
                console.log(this.msg);
                console.log(this.test);
                console.log(this.$el);
                console.log(this.$refs.testDom);
            },
            //vue实例挂载后 配置项都初始化，根元素也初始化，可以操作Dom元素
            mounted(){
                console.log('mounted');
                console.log(this.msg);
                console.log(this.test);
                console.log(this.$el);
                console.log(this.$refs.testDom);
            },
            //页面更改之前
            beforeUpdate(){
                console.log('beforeUpdate');
            },
            //页面更改之后
            updated(){
                console.log('updated');
            },
            //销毁之前
            beforeDestroy(){
                console.log('beforeDestroy');
            },
            //销毁之后
            destroyed(){
                console.log('destroy');
            }
        })
    </script>
</body>

</html>